// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })

const db = cloud.database()
// 云函数入口函数
exports.main = async (event) => {
    const { locationId, userId } = event;
    const { data } = await db.collection('userInfo').doc(userId).get();
    const likeLocationIds = data.likeLocationIds || []
    await db.collection('userInfo').doc(userId).update({
        data: {
            likeLocationIds: likeLocationIds.includes(locationId) ? likeLocationIds.filter(item => item !== locationId) : [...likeLocationIds, locationId]
        }
    })

    return {
        data: {
            message: '操作成功',
            code: 200
        }
    }
}